package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.LinkedList;
import java.util.List;

import com.example.myapplication.R;
import com.example.myapplication.Person;
import com.example.myapplication.MyAdapter;

public class ListViewActivity extends AppCompatActivity {

    private ListView btnList;
    private String[] name = {"企业级开发框架", "移动应用开发", "web前端框架应用","深度学习","计算机视觉"};
    private int[] xuefen = {1, 2, 3, 3 , 2 };
    private int[] maxNum = {3,3,3,3,3};
    private int[] selectedNum = {0,0,0,0,0};
    private int[] imgId = {R.drawable.spring, R.drawable.android, R.drawable.web,R.drawable.python,R.drawable.opcv};

    private Button btn_selected;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);

        List<Person> personList = new LinkedList<>();
        for (int i = 0; i < name.length; i++) {
            Person person = new Person();
            person.setImgIcon(imgId[i]);
            person.setName(name[i]);
            person.setXuefen(xuefen[i]);
            person.setMaxNum(maxNum[i]);
            person.setSelectedNum(selectedNum[i]);
            personList.add(person);
        }

        btnList = (ListView) findViewById(R.id.btnList);
        MyAdapter adapter = new MyAdapter(this, personList);
        btnList.setAdapter(adapter);

        btn_selected = findViewById(R.id.btn_selected);
//        切换已选课程
        btn_selected.setOnClickListener((v)->{
            Intent intent = new Intent();
            intent.setClass(ListViewActivity.this,SelectedActivity.class);
            startActivity(intent);
        });
    }
}